//Copyright (c) 2006-2007 Microsoft Corporation.  All rights reserved
using System;
using System.Transactions;

namespace InvocationFramework.Adapters.Inproc.Transactions
{
    /// <summary>
    /// Helper para el manejo de transacciones
    /// </summary>
    /// <author>Rodolfo Finochietti 30/12/2005 11.37</author>
    public static class TransactionManager
    {
        #region Properties

        /// <summary>
        /// Devuelve la fecha y hora de creacion de la transaccion
        /// </summary>
        public static DateTime CreationTime
        {
            get
            {
                if ( IsInTransaction )
                    return Transaction.Current.TransactionInformation.CreationTime;
                else
                    return DateTime.MinValue;
            }
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// Aborta la transaccion actual
        /// </summary>
        public static void Rollback( )
        {
            if ( IsInTransaction )
                Transaction.Current.Rollback( );
        }

        /// <summary>
        /// Permita saber si el contexto actual es transacional
        /// </summary>
        public static bool IsInTransaction
        {
            get
            {
                return Transaction.Current != null;
            }
        }

        #endregion
    }
}